package com.app.mvc.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.app.mvc.dao.AbstractHibernateDaoSupport;
import com.app.mvc.dao.DealImageDao;
import com.app.mvc.model.DealImage;
import com.app.mvc.ultil.HibernateUtil;

public class DealImageDaoImpl extends
		AbstractHibernateDaoSupport<DealImage, Long> implements DealImageDao {

	public DealImageDaoImpl() {
		super(DealImage.class);
		// TODO Auto-generated constructor stub
	}

	@Override
	@SuppressWarnings("unchecked")
	public List<DealImage> getImageByDeal(long deal_id) {
		// TODO Auto-generated method stub
		Criteria criteria = HibernateUtil.getSession()
				.createCriteria(DealImage.class)
				.setFetchMode("deal", FetchMode.JOIN)
				.add(Restrictions.eq("deal.id", deal_id))
				.addOrder(Order.desc("id"));
		return criteria.list();
	}

}
